<template>
  <div>
    <van-cell-group title="交通事故计算结果">
      <van-cell title="医疗费" :value="result.hospital_fee" />
      <van-cell title="交通费" :value="result.car_fee" />
      <van-cell title="住宿费" :value="result.hotel_fee" />
      <van-cell title="鉴定费" :value="result.appraise_fee" />
      <van-cell title="伤残辅助器具费" :value="result.device_cost" />
      <van-cell title="误工费" :value="result.delay_fee" />
      <van-cell title="护理费" :value="result.nurse_fee" />
      <van-cell title="住院伙食补助费" :value="result.food_allowance" />
      <van-cell title="护理依赖费" :value="result.nurse_denpendence" />
      <van-cell title="营养费" :value="result.nutrition_fee" />
      <van-cell title="伤残赔偿金" :value="result.disability_fee" />
      <van-cell title="死亡赔偿金" :value="result.dead_compensation_fee" />
      <van-cell
        title="被抚(扶)养人生活费"
        :value="result.supported_living_expense"
      />
      <van-cell title="丧葬费" :value="result.funeral_expense" />
      <van-cell title="精神抚慰金" :value="result.spirit_fee" />
      <van-cell title="其他费用" :value="result.other_fee" />
      <van-cell title="整容费" :value="result.cosmetic_fee" />
      <van-cell title="财产损失" :value="result.asset_lost" />
      <van-cell
        v-for="(item, index) in result.other_incomes"
        :title="item.name"
        :value="item.money | format"
        :key="index"
      />

      <van-cell title="合计" :value="result.totals_fee" class="cell-bottom" />
    </van-cell-group>
  </div>
</template>

<script>
// import { calcTraffic } from "@/api/calculator";
export default {
  name: "Traffic_result",
  data() {
    return {
      result: {},
    };
  },
  filters: {
    //数据过滤器
    format: function (value) {
      value = Number(value).toFixed(2) + "元";
      return value;
    },
  },
  computed: {},
  methods: {
    getData() {
      const data = sessionStorage.getItem("calc_results");
      const obj = JSON.parse(data);
      for (let prop in obj) {
        if (prop == "other_incomes") continue;

        if (isNaN(obj[prop])) {
          obj[prop] = (0.0).toFixed(2) + "元";
        } else {
          obj[prop] = obj[prop].toFixed(2) + "元";
        }
      }
      this.result = obj;
      console.log(this.result);
    },
  },
  created() {
    this.getData();
  },
};
</script>

<style  scoped>
.van-cell-group__title {
  background-color: #f5f5f5;
}
.cell-bottom {
  background-color: #f5f5f5;
  font-weight: bold;
  margin-bottom: 20px;
}
.value-align {
  text-align: left;
}
</style>